﻿using log4net.Config;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using log4net.Repository;

namespace IPC.LogCommon.log4net
{
    public class LogClass
    {
        #region 单例
        private static LogClass _instance;
        private static readonly object _lock = new object();
        public static LogClass Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_lock)
                    {
                        if(_instance == null)
                        {
                            _instance = new LogClass();
                        }
                    }
                }
                return _instance;
            }
        }
        #endregion

        private ILoggerRepository _loggerRepository;
        private ILog log;

        public LogClass() {
            _loggerRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
            FileInfo fileInfo = new FileInfo("log4net/log4net.config");
            XmlConfigurator.Configure(_loggerRepository, new FileInfo("log4net/log4net.config"));
            log = LogManager.GetLogger(_loggerRepository.Name, "IPCProject");
        }

        /// <summary>
        /// 信息
        /// </summary>
        /// <param name="msg"></param>
        public void Info(string msg)
        {
            log.Info(msg);
        }

        /// <summary>
        /// 报错
        /// </summary>
        /// <param name="msg"></param>
        public void Error(string msg)
        {
            log.Error(msg);
        }

        /// <summary>
        /// 严重警告
        /// </summary>
        /// <param name="msg"></param>
        public void Fatal(string msg)
        {
            log.Fatal(msg);
        }
        /// <summary>
        /// 调试
        /// </summary>
        /// <param name="msg"></param>
        public void Debug(string msg) { 
            log.Debug(msg);
        }

        /// <summary>
        /// 警告
        /// </summary>
        /// <param name="msg"></param>
        public void Warn(string msg)
        {
            log.Warn(msg);
        }
    }
}
